package com.yunze.system.service.impl.yunze.fhgl;

import com.yunze.common.mapper.mysql.fhgl.FhglExpressDeliveryMapper;
import com.yunze.common.mapper.mysql.fhgl.FhglExpressDeliveryStaffMapper;
import com.yunze.common.utils.yunze.ID_Generate;
import com.yunze.common.utils.yunze.PageUtil;
import com.yunze.system.service.yunze.fhgl.IFhglExpressDeliveryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class FhglExpressDeliveryServiceImpl implements IFhglExpressDeliveryService {
    @Resource
    private FhglExpressDeliveryMapper fhglExpressDeliveryMapper;
    @Resource
    private FhglExpressDeliveryStaffMapper fhglExpressDeliveryStaffMapper;


    @Override
    public boolean add_EDY(Map<String, Object> map)  {
        boolean bool=false,EDY_bool=false,EDSF_bool=false;
        Map<String, Object> EDY_Map=(Map<String, Object>) map.get("EDY_Map");
        
        Integer EDY_ID_CT = fhglExpressDeliveryMapper.sel_data_count();//查询今日注册供应商数量
        EDY_ID_CT=EDY_ID_CT!=null?EDY_ID_CT:0;//如果今日添加为0会反回null,给个默认值0
        String EDY_ID=ID_Generate.G_id("FEDY", EDY_ID_CT, 4);//生成ID
        EDY_Map.put("EDY_ID", EDY_ID);//赋值id
        EDY_bool = fhglExpressDeliveryMapper.add_EDY(EDY_Map)>0;//添加快递公司信息
        map.put("EDY_ID", EDY_ID);//赋值快递公司员工信息所属id
        EDSF_bool = fhglExpressDeliveryStaffMapper.add_EDSF(map)>0;//添加详情
        if(EDY_bool==true && EDSF_bool==true) {
            bool=true;
        }
        return bool;
    }

    @Override
    public Map<String, Object> selMap(Map<String, Object> map)  {
        Map<String, Object> Rmp=new HashMap<String, Object>();
        Integer currenPage=map.get("pageNum")!=null?Integer.parseInt(map.get("pageNum").toString()):0;
        Integer pageSize=map.get("pageSize")!=null?Integer.parseInt(map.get("pageSize").toString()):10;
        Integer rowCount = fhglExpressDeliveryMapper.selMapCount(map);
        rowCount=rowCount!=null?rowCount:0;
        PageUtil pu=new PageUtil(rowCount,currenPage , pageSize);//初始化分页工具类
        //数据打包
        map.put("StarRow", pu.getStarRow());
        map.put("PageSize", pu.getPageSize());
        Rmp.put("Pu", pu);
        Rmp.put("Data", fhglExpressDeliveryMapper.selMap(map));
        return  Rmp;
    }

    @Override
    public Map<String, Object> find_data(Map<String, Object> map)  {
        Map<String, Object> mmp =new HashMap<String, Object>();
        mmp.put("EDY_Map", fhglExpressDeliveryMapper.find_data(map));
        mmp.put("EDSF_arr", fhglExpressDeliveryStaffMapper.find_data(map));
        return mmp;
    }

    @Override
    public boolean upd_EDY(Map<String, Object> map)  {
        boolean bool=false,EDY_bool=false,EDSF_bool=false;
        Map<String, Object> EDY_Map=(Map<String, Object>) map.get("EDY_Map");
        EDY_bool = fhglExpressDeliveryMapper.upd_EDY(EDY_Map)>0;//修改
            fhglExpressDeliveryStaffMapper.del_EDSF(map);//新增详情前先删除之前的数据
        EDSF_bool = fhglExpressDeliveryStaffMapper.add_EDSF(map)>0;//添加详情
        if(EDY_bool==true && EDSF_bool==true) {
            bool=true;
        }
        return bool;
    }

    @Override
    public boolean del_EDY(Map<String, Object> map)  {
        fhglExpressDeliveryStaffMapper.del_EDSF(map);//删除 快递公司详情
        return fhglExpressDeliveryMapper.del_EDY(map)>0;
    }

    @Override
    public List<Map<String, Object>> sel_date()  {
        return fhglExpressDeliveryMapper.sel_date();
    }





    



}
















